package com.bdqn.ch06.controller;


import com.bdqn.ch06.entity.User;
import com.bdqn.ch06.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
public class ExampleController {
    @Resource
    private UserService userService;

    @GetMapping(value = "hello/{id}")
    public String getUser(@PathVariable("id")Long usrId, Model model){
        User user=userService.getUser(usrId);
        model.addAttribute("user",user);
        return "demo/hello";
    }

    @GetMapping(value = "/string")
    public String getString(Model model,HttpServletRequest request){
        model.addAttribute("usrName","科加斯");
        request.setAttribute("test",request);
        request.getSession().setAttribute("test","session");
        model.addAttribute("date",new Date());
        return "demo/string";
    }
}
